package com.movitech.mobile.ddzy.modules.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.movitech.mobile.cz.base.common.util.HttpUtil;
import com.movitech.mobile.cz.base.common.util.StringUtils;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.sessionuser.SessionMenuService;
import com.movitech.mobile.cz.base.sessionuser.SessionMenuVo;
import com.movitech.mobile.cz.base.sessionuser.SessionUserVo;
import com.movitech.mobile.cz.base.util.UserUtils;
import com.movitech.mobile.ddzy.bpm.feignclient.MbsAuthClient;

@Service("extSessionMenuService")
public class SessionMenuServiceImpl implements SessionMenuService {

	@Value("${api.feign.auth.appuuid}")
	private String apiFeignAuthAppuid;

    @Autowired
    MbsAuthClient mbsAuthClient;

	@Override
	public List<SessionMenuVo> getSessionMenu() {
		List<SessionMenuVo> lstSessionMenuVo = null;
		try {
			Gson gson = new Gson();
			SessionUserVo sessionUserVo = UserUtils.getCurrentUserVo();
			if (sessionUserVo != null) {
				String employeeId = sessionUserVo.getEmployeeID();
				String returnJson = mbsAuthClient.getauth(employeeId,apiFeignAuthAppuid);//HttpUtil.sendGet(mbsAuthUrl+employeeId);
				System.out.println("===菜单===" + returnJson);
				if (StringUtils.isNotEmpty(returnJson)) {
					RestReturnResult<List<SessionMenuVo>> result = gson.fromJson(returnJson, new TypeToken<RestReturnResult<List<SessionMenuVo>>>() {
					}.getType());
					if (result != null) {
						lstSessionMenuVo = result.getData();
					}
				}
//			String result = mbsAuthClient.getauth(apiFeignAuthAppuid, employeeId);
//			if(result!=null){
//				lstSessionMenuVo = result.getData();
//			}
			}
		}catch (Exception e){
			e.printStackTrace();
		}
		return lstSessionMenuVo;
	}
}
